package com.xiaojie.dubbo.server.loadBalance;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
/*
 * 轮训算法
 * @param null 
 * @todo
 * @author xiaojie 
 * @date 2021/8/6 11:13
 * @return 
 */
public class LoopBalance  implements  LoadBalance<String>{
//    private int index;

    private AtomicInteger atomicInteger=new AtomicInteger(0);
    @Override
    public String select(List<String> repos) {
        int index = atomicInteger.incrementAndGet() % repos.size();
        return repos.get(index);
    }


  /*  public  synchronized String select(List<String > repos) {
        if (index>= repos.size()){
            index=0;
        }
        String  value = repos.get(index++);
        return  value;
    }*/
}
